<template>
  <div>
      <van-address-list
        :list="list"
        default-tag-text="默认"
        @add="onAdd"
        @edit="onEdit"
        @select="select($event)"
      />
      <van-empty v-if="list.length == 0" description="暂无数据" />
  </div>
</template>

<script>
import { reqAddressList } from "../../http/http";
export default {
 data(){
   return  {
     list:[]
   }
 },
 activated(){
   reqAddressList({
      uid:JSON.parse(localStorage.getItem("userInfo")).uid,
   }).then(res=>{
    //  console.log(res);
     if(res.data.code === 200){
       let arr = res.data.list ? res.data.list : [];
      //  将后端取回来的数据 转换为UI需要的字段
      // map 数组方法 遍历数组 返回一个新的数组
      this.list =  arr.map( (item) => {
          return {
            id:item.id,
            name:item.username,
            tel:item.userphone,
            address:item.location + item.useraddress,
            isDefault: item.status===1
          };
      });
     }
   });
 },
 methods:{
   onAdd(){
      this.$router.push("/newaddress")
   },
   onEdit(e){
    //  console.log(1);
      this.$router.push("/newaddress?id=" + e.id);
   },
   select(e){
     this.$router.replace("/order?addressId="+ e.id)
   }
 }
}
</script>

<style spoced>
.bootom{
  position:fixed;
  width: 80vw;
  left: 0;
  margin-left: 10%;
  bottom: 0;
}
</style>